package cn.meomis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.meomis.dao.UserDao;
import cn.meomis.model.User;
import cn.meomis.service.UserService;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	@Override
	public List<User> findAll() {
		return userDao.getAll();
	}
	
	@Override
	public User findById(Integer id) {
		return userDao.findById(id);
	}
	
	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void save(User user) {
		userDao.save(user);
	}
	
	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void removeById(Integer id) {
		User user = userDao.findById(id);
		userDao.delete(user);
	}

}
